<?xml version="1.0"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
{% spaceless %}
    <channel>
        <title>{{ site_title }}</title>
        <link>{{ base_url }}</link>
        <atom:link href="{{ current_page.url }}" rel="self" type="application/rss+xml" />
        <description>
            {% if config.tagblog.site_description %}
                {{ config.tagblog.site_description }}
            {% else %}
                Blog feed
            {% endif %}
        </description>
        {# <language>en-us</language> #}
        <pubDate>{{ "now"|date("r") }}</pubDate>
        <lastBuildDate>{{ "now"|date("r") }}</lastBuildDate>

        {% if config.tagblog.feed.limit %}
            {% set limit = config.tagblog.feed.limit %}
        {% else %}
            {% set limit = 10 %}
        {% endif %}
        {# it is not easy to break out of a loop in twig: stackoverflow.com/a/29161205 #}
        {% set break = false %}
        {% set count = 0 %}
        {% for page in pages if not break %}
            {% if page.meta.tags %}
                <item>
                    <title>{{ page.title }}</title>
                    <link>{{ page.url }}</link>
                    <pubDate>{{ page.date_formatted|date("r") }}</pubDate>
                    {% if page.author %}
                        <author>{{ page.author }}</author>
                    {% endif %}
                    {% for tag in page.meta.tags|split(',') %}
                        <category>{{ tag }}</category>
                    {% endfor %}
                    <guid>{{ page.url }}</guid>
                    <description><![CDATA[{% if page.description %}{{ page.description }}{% else %}{{ page.id|content|striptags|slice(0, 300) }}...{% endif %}]]></description>
                    {% if config.tagblog.feed.content is defined and config.tagblog.feed.content %}
                        <content:encoded><![CDATA[{{ page.id|content }}]]></content:encoded>
                    {% endif %}

                </item>
                {% set count = count + 1 %}
                {% if count == limit %}{% set break = true %}{% endif %}
            {% endif %}
        {% endfor %}
    </channel>
{% endspaceless %}
</rss>
